package com.ruoyi.web.personal.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.personal.domain.Personal;
import com.ruoyi.web.personal.service.IPersonalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员管理Controller
 * 
 * @author bxm
 * @date 2025-07-30
 */
@RestController
@RequestMapping("/personal/personal")
public class PersonalController extends BaseController
{
    @Autowired
    private IPersonalService personalService;

    /**
     * 查询人员管理列表
     */
    @PreAuthorize("@ss.hasPermi('personal:personal:list')")
    @GetMapping("/list")
    public TableDataInfo list(Personal personal)
    {
        startPage();
        List<Personal> list = personalService.selectPersonalList(personal);
        return getDataTable(list);
    }

    /**
     * 导出人员管理列表
     */
    @PreAuthorize("@ss.hasPermi('personal:personal:export')")
    @Log(title = "人员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Personal personal)
    {
        List<Personal> list = personalService.selectPersonalList(personal);
        ExcelUtil<Personal> util = new ExcelUtil<Personal>(Personal.class);
        util.exportExcel(response, list, "人员管理数据");
    }

    /**
     * 获取人员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('personal:personal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(personalService.selectPersonalById(id));
    }

    /**
     * 新增人员管理
     */
    @PreAuthorize("@ss.hasPermi('personal:personal:add')")
    @Log(title = "人员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Personal personal)
    {
        return toAjax(personalService.insertPersonal(personal));
    }

    /**
     * 修改人员管理
     */
    @PreAuthorize("@ss.hasPermi('personal:personal:edit')")
    @Log(title = "人员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Personal personal)
    {
        return toAjax(personalService.updatePersonal(personal));
    }

    /**
     * 删除人员管理
     */
    @PreAuthorize("@ss.hasPermi('personal:personal:remove')")
    @Log(title = "人员管理", businessType = BusinessType.DELETE)
	@PutMapping("/del")
    public AjaxResult remove(@RequestBody Long ids)
    {
        return toAjax(personalService.deletePersonalByIds(ids));
    }
}
